<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>检查指定字符串结尾</title>
</head>
<body>
    <script>
        var str1 = 'abcdacba';  //8 6
        var str2 = 'abcdefg';   //7 5
        var str3 = 'asd';       //3 1

        function isEndstr(str,endStr){
            // 获取指定字符串在原字符串的起始索引值
            var startIdx = str.length - endStr.length;
            
            // 确保索引值从0开始
            if(startIdx >= 0 &&str.indexOf(endStr) === startIdx){
                return true
            }else{
                return false
            }

        }
        console.log(isEndstr(str3,'aaasd'));
    </script>
</body>
</html>